Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api: return users details by groups #8904

Merged
merged 8 commits into from
Apr 6, 2018

Conversation

skjnldsv
Copy link
Member

@skjnldsv skjnldsv commented Mar 20, 2018

This allows to get the users detailed data directly by requesting the groupid

$.get(OC.linkToOCS('cloud/groups/admin/users',2)+'details').then((response)=>console.log(response))
$.get(OC.linkToOCS('cloud/groups/admin/users',2)+'details?limit=10').then((response)=>console.log(response))
$.get(OC.linkToOCS('cloud/groups/admin/users',2)+'details?limit=2&offset=2').then((response)=>console.log(response))

@skjnldsv skjnldsv added this to the Nextcloud 14 milestone Mar 20, 2018
@skjnldsv skjnldsv self-assigned this Mar 20, 2018
@skjnldsv skjnldsv mentioned this pull request Mar 21, 2018
34 tasks
// Check subadmin has access to this group
if($this->groupManager->isAdmin($user->getUID())
|| $isSubadminOfGroup) {
$users = $this->groupManager->get($groupId)->getUsers();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you already got the group in 210,
also here the null check is missing.

$user = $this->userSession->getUser();

// Check the group exists
if(!$this->groupManager->groupExists($groupId)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to get the group here and use the check for null to error out.
If you got a group don't check it any further

@skjnldsv skjnldsv force-pushed the ocs-api-get-users-details-per-groups branch from cac9609 to 0db5c79 Compare March 22, 2018 14:40
@codecov
Copy link

codecov bot commented Mar 22, 2018

Codecov Report

Merging #8904 into master will decrease coverage by 0.09%.
The diff coverage is 58.4%.

@@             Coverage Diff             @@
##             master    #8904     +/-   ##
===========================================
- Coverage     51.97%   51.87%   -0.1%     
+ Complexity    25287    25285      -2     
===========================================
  Files          1601     1602      +1     
  Lines         94984    94996     +12     
  Branches       1388     1388             
===========================================
- Hits          49366    49283     -83     
- Misses        45618    45713     +95
Impacted Files Coverage Δ Complexity Δ
...isioning_api/composer/composer/autoload_static.php 0% <ø> (ø) 1 <0> (ø) ⬇️
apps/provisioning_api/appinfo/routes.php 0% <0%> (ø) 0 <0> (ø) ⬇️
...ioning_api/composer/composer/autoload_classmap.php 0% <0%> (ø) 0 <0> (ø) ⬇️
...rovisioning_api/lib/Controller/UsersController.php 75% <100%> (+1.63%) 127 <0> (-13) ⬇️
...ovisioning_api/lib/Controller/GroupsController.php 68.88% <38.63%> (-23.97%) 27 <14> (+2)
apps/provisioning_api/lib/Controller/AUserData.php 68.11% <68.11%> (ø) 12 <12> (?)
lib/private/Files/ObjectStore/Swift.php 0% <0%> (-72.42%) 9% <0%> (ø)
lib/private/Files/ObjectStore/SwiftFactory.php 0% <0%> (-51%) 37% <0%> (ø)
apps/files/lib/Controller/ViewController.php 77.19% <0%> (-1.15%) 18% <0%> (ø)
lib/private/Files/Mount/Manager.php 100% <0%> (ø) 23% <0%> (-2%) ⬇️
... and 6 more

@skjnldsv skjnldsv force-pushed the ocs-api-get-users-details-per-groups branch from 0db5c79 to e92f640 Compare March 22, 2018 14:52
@skjnldsv skjnldsv requested a review from nickvergessen March 22, 2018 15:06
@skjnldsv
Copy link
Member Author

Ready for review again.
@nickvergessen

@@ -42,6 +42,7 @@
// Users
['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#getUsersDetails', 'url' => '/users/details', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#getUsersGroupDetails', 'url' => '/users/{groupId}/details', 'verb' => 'GET'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route doesn't really fit the schema of the others. Maybe something like /groups/{groupId}/users would make more sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked myself the same question, and was rather confuse, do we extract tehe users by groups or do we get the users in group :)
Therefore my current choice, especially since the getUsersData function is in the UsersController :)

Copy link
Member Author

@skjnldsv skjnldsv Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And since /groups/{groupId}/ actually return the users, shouldn't we go for something like /groups/{groupId}/details? It really lokks like groups-informations related data. I would prefer something like /groups/{groupId}/users/details but /groups/{groupId}/users doesn't exists :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/groups/{groupId}/details sounds good to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such url is supposed to return the details of the group, like we have in /groups/details :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had teh same weird feeling on the url,
it doesn't feel right to me, maybe a ?group=<filter> on the current endpoint is the better option?

$isSubadminOfGroup = false;
$group = $this->groupManager->get($groupId);
if ($group !== null) {
$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminofGroup($user, $group);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isSubAdminofGroup -> isSubAdminOfGroup

if ($group !== null) {
$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminofGroup($user, $group);
} else {
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\OCP\API is deprecated, see OCSNotFoundException

}, $users);
$users = array_slice(array_values($users), $offset, $limit);
} else {
throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\OCP\API is deprecated, see OCSForbiddenException

@skjnldsv skjnldsv force-pushed the ocs-api-get-users-details-per-groups branch 8 times, most recently from f428a0b to d473653 Compare March 23, 2018 17:02
@skjnldsv
Copy link
Member Author

skjnldsv commented Mar 23, 2018

Ready for reviews again! :)

$.get(OC.linkToOCS('cloud/groups/admin/users',2)+'details').then((response)=>console.log(response))
$.get(OC.linkToOCS('cloud/groups/admin/users',2)+'details?limit=10').then((response)=>console.log(response))
$.get(OC.linkToOCS('cloud/groups/admin/users',2)+'details?limit=2&offset=2').then((response)=>console.log(response))

@skjnldsv skjnldsv requested a review from juliusknorr March 23, 2018 17:25
@skjnldsv skjnldsv dismissed stale reviews from juliusknorr and nickvergessen March 23, 2018 17:25

Fixed

@@ -36,6 +36,8 @@
['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroupsDetails', 'url' => '/groups/details', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroupUsers', 'url' => '/groups/{groupId}/users', 'verb' => 'GET'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallback to proper url design, above one is deprecated!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a note about this to #7827? But I guess it's not easily possible to drop this as it is part of the OCS standard 😉

*/
public function __construct(
string $appName,
IRequest $request,
IGroupManager $groupManager,
IUserSession $userSession,
ILogger $logger) {
ILogger $logger,
UsersController $userController) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead extract the shared logic in a subclass/trait?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nickvergessen what would you suggest to have a clean logic?

use OCP\AppFramework\OCSController;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\IUser;
use OCA\Provisioning_API\Controller\UsersController;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be needed

$offset = (int)$offset;
}

public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit is not checked for null anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we use slice to cut our arrays, null will be ignored. :)
array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = FALSE ]] )
https://secure.php.net/manual/en/function.array-slice.php

@skjnldsv skjnldsv force-pushed the ocs-api-get-users-details-per-groups branch 2 times, most recently from 4b4f4dc to 9b081c8 Compare March 27, 2018 07:48
* @throws OCSException
*/
public function getUserData(string $userId): array {
$currentLoggedInUser = $this->userSession->getUser();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm php storm doesn't know userSession. I guess you need to declare it in this trait too.

@nickvergessen nickvergessen force-pushed the ocs-api-get-users-details-per-groups branch from 1663ec5 to 5d13464 Compare March 27, 2018 09:07
@skjnldsv
Copy link
Member Author

skjnldsv commented Apr 3, 2018

Bump, failure unrelated (swift) :)

* @return DataResponse
* @throws OCSException
*
* @deprecated 14 Use getGroupUsers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a note about this to #7827? But I guess it's not easily possible to drop this as it is part of the OCS standard 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought it was the better way. It's not that bad tough :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the changelog in #7827

Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works 👍

@rullzer
Copy link
Member

rullzer commented Apr 4, 2018

CONFLICTS!!! ⚠️ 😱 🙀

skjnldsv and others added 8 commits April 5, 2018 17:08
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
@skjnldsv skjnldsv force-pushed the ocs-api-get-users-details-per-groups branch from 5d13464 to eb4d7fb Compare April 5, 2018 15:13
@skjnldsv
Copy link
Member Author

skjnldsv commented Apr 5, 2018

Failure unrelated: swift :)
@rullzer

Copy link
Member

@rullzer rullzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do this!

@rullzer rullzer merged commit 4a6e31c into master Apr 6, 2018
@rullzer rullzer deleted the ocs-api-get-users-details-per-groups branch April 6, 2018 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants